#include<stdio.h>
#include<queue>
using namespace std;
const int maxn=1000;
priority_queue<int,vector<int>,greater<int> > q;
int main()
{
	int a[maxn],n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		q.push(a[i]);
	}
	int x,y,sum=0;
	while(q.size()>1){
		x=q.top();
		q.pop();
		y=q.top();
		q.pop();
		q.push(x+y);
		sum+=x+y;
	}
	printf("%d",sum);
	return 0;
}
